package com.lucaswangdev.model.convert;

import com.alibaba.fastjson.JSON;
import com.lucaswangdev.biz.request.workOrder.WorkOrderCreateRequest;
import com.lucaswangdev.biz.request.workOrder.WorkOrderUpdateRequest;
import com.lucaswangdev.model.domain.WorkOrderDO;
import com.lucaswangdev.model.dto.WorkOrderDTO;
import com.lucaswangdev.web.vo.WorkOrderVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;
import java.util.Collections;
import java.util.List;

@Mapper(componentModel = "spring")
public interface WorkOrderConverter {
    WorkOrderConverter INSTANCE = Mappers.getMapper(WorkOrderConverter.class);

    @Mappings({
                })
    WorkOrderDTO convertRequest2DTO(WorkOrderCreateRequest request);

    @Mappings({
                })
    WorkOrderDTO convertRequest2DTO(WorkOrderUpdateRequest request);

    @Mappings({
    })
    WorkOrderDTO convertDO2DTO(WorkOrderDO workOrderDO);

    @Mappings({
    })
    WorkOrderDO convertDTO2DO(WorkOrderDTO workOrderDTO);

    List<WorkOrderVO> convertDTOList2VOList(List<WorkOrderDTO> tableData);

    @Mappings({
                })
    WorkOrderVO convertDTO2VO(WorkOrderDTO workOrderDTO);

    @Named("listToJsonString")
    default String listToJsonString(List<String> list){
        return list == null ? null : JSON.toJSONString(list);
    }

    @Named("jsonStringToList")
    default List<String> jsonStringToList(String jsonString){
        if(jsonString == null) {
            return Collections.emptyList();
        }
        return JSON.parseArray(jsonString, String.class);
    }
}
